var branchCompanyData = [];

$(document).ready(function() {
	showLoading();
	$('title', parent.document).html($('title').text());
	setBaseUrl();
	addTitle("branchCompanyUpdate");
	search();
	setTimeout(hideLoading, 500);
});

function search() {
	$('#BranchCompanyName').val($("#detailID", parent.document).val());
	$ajax('searchBranchCompany', 'searchBranchCompanyUpdate', searchBranchCompany);
	$("#detailID", parent.document).val("");
}
function searchBranchCompany(data){
	branchCompanyData = data && data.branchCompanyList || [];
	createComBody("detailOneBody", branchCompanyTable, branchCompanyData[0], 1);
	$("#branchCompanyID").attr("readonly", true);
	$('#confirm').show();
	if(branchCompanyData[0].enabled == true){
		$("#enabled").val(1);
	}else{
		$("#enabled").val(0);
	}
}
function updateBranchCompany(data){
	 var result = data && data.result;
     if (result == "Success"){
    	 showMessge(messageContent["Update.Success"], undefined, goback);
     } else if (result == "NotFound"){
    	 showMessge(messageContent["Update.Failed"]);
     } else if (result == "BranchCompanyNameExist"){
         showMessge(messageContent["BranchCompany.BranchCompanyNameExist"]);
     } else{
    	 showMessge(messageContent["Update.Error"]);
     }
}
function confirm(){
	return checkForm("saveForm", branchCompanyTable);
}
function goback() {
	window.parent.skipMenu('chargingStation/branchCompany', 'drownDown1', '', 'chargingStationPage', 'branchCompany');
}